package com.lqk.demo.concurrencytools.threadpool.executors.tasksubmit;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author lqk
 * @date 2022/1/7 15:14
 *
 * 提交任务 task，用返回值 Future 获得任务执行结果
 * <T> Future<T> submit(Callable<T> task);
 */
@Slf4j
public class TestSubmit {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(2);

        Future<String> future = pool.submit(() -> {
            Thread.sleep(1000);
            return "ok";
        });

        log.debug(future.get());
    }
}
